<template>
  <div class="panle">
    <h1 class="title">后台管理系统</h1>
    <el-tabs type="border-card" stretch class="tabs" v-model="currentTab">
      <el-tab-pane name="account">
        <template #label>
          <span>
            <el-icon><User /></el-icon>
            <span>账号登录</span>
          </span>
        </template>
        <template #default>
          <login-account ref="accountRef" />
        </template>
      </el-tab-pane>
      <el-tab-pane name="phone">
        <template #label>
          <span>
            <el-icon><Iphone /></el-icon>
            <span>手机登录</span>
          </span>
        </template>
        <template #default><login-phone ref="phoneRef" /></template>
      </el-tab-pane>
    </el-tabs>

    <div class="psw-control">
      <el-checkbox v-model="isKeepPsw">记住密码</el-checkbox>
      <el-link type="primary" :underline="false">忘记密码</el-link>
    </div>

    <el-button type="primary" class="login-btn" @click="login"> 立即登录 </el-button>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { User, Iphone } from '@element-plus/icons-vue'
import LoginAccount from './login-account.vue'
import LoginPhone from './login-phone.vue'

const currentTab = ref('account')
const isKeepPsw = ref(true)
const accountRef = ref<InstanceType<typeof LoginAccount>>()
const phoneRef = ref<InstanceType<typeof LoginPhone>>()

const login = () => {
  // console.log('立即登录')
  if (currentTab.value === 'account') {
    accountRef.value?.loginAction(isKeepPsw.value)
  } else {
    phoneRef.value?.phoneLogin()
  }
}
</script>

<style scoped lang="less">
.panle {
  width: 320px;
  text-align: center;
  margin-bottom: 150px;
  .tabs .el-icon {
    vertical-align: middle;
    margin-right: 4px;
  }
  .tabs span {
    vertical-align: middle;
  }

  .psw-control {
    display: flex;
    justify-content: space-between;
  }

  .login-btn {
    width: 100%;
    margin-top: 10px;
  }
}
</style>
